{% extends "base.html" %}
{% block mainbody %}
{#  注意引入文件的方式  #}
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
<script src="/static/layui/layui.js"></script>
<script language="JavaScript">
    function getCookie(c_name) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=")
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1
                c_end = document.cookie.indexOf(";", c_start)
                if (c_end == -1) c_end = document.cookie.length
                return unescape(document.cookie.substring(c_start, c_end))
            }
        }
        return ""
    }
    retcook = getCookie('AGraph_AJQCDJOWN63628df')
    if (retcook == "") {
        window.location.href = "/login";
    } else {
    }
</script>


<script>
    var glob_labels = []
    var glob_relations = []

    var form_data = new FormData();
    $.ajax({
        url: "/get_lable_re_math/",
        type: "POST",
        data: form_data,
        //async: false,
        contentType: false,
        processData: false,
        success: function (cur_data) {
            glob_labels = cur_data.labelsret
            glob_relations = cur_data.relationshiptypesret


            var html = '<option value="">选取子图关系</option>'
            html = html + '<option value="不限关系">不限关系</option>'
            for (var i = 0; i < glob_relations.length; i++) {
                html = html + '<option value="' + glob_relations[i]['relationshipType'] + '">' + glob_relations[i]['relationshipType'] + '</option>'
            }
            var addtemp = document.getElementById('grouplayfilterid');
            addtemp.innerHTML = html
            var addtemp = document.getElementById('pankrangelayfilterid');
            addtemp.innerHTML = html
            /*
                        var addtemp = document.getElementById('circlerelayfilterid');
                        addtemp.innerHTML = html
            
                        var html = '<option value="">选取边类型</option>'
                        html = html + '<option value="不限类型">不限类型</option>'
                        for (var i = 0; i < glob_relations.length; i++) {
                            html = html + '<option value="' + glob_relations[i]['relationshipType'] + '">' + glob_relations[i]['relationshipType']  + '</option>'
                        }
                        var addtemp = document.getElementById('circlerelayfilterid');
                        addtemp.innerHTML = html
            
                        var html = '<option value="">选取目标实体类型</option>'
                        for (var i = 0; i < glob_labels.length; i++) {
                            html = html + '<option value="' + glob_labels[i]['label'] + '">' + glob_labels[i]['label']  + '</option>'
                        }
                        var addtemp = document.getElementById('circleenlayfilterid');
                        addtemp.innerHTML = html
            */
        },
        error: function () {
            alert("获取图类型、图关系失败，请检查图数据库链接");
        }
    })
</script>
<div class="container">
    <div class="row">
        <!--head start-->
        <h3 class="page-header"><i class="fa fa-share-alt" aria-hidden="true"></i> 图计算 </h3>

        <div class="col-md-12">
            <ol class="breadcrumb">
                <li><i class="fa fa-share-alt" aria-hidden="true"></i>社区发现模型</li>
            </ol>
            <p>社区发现模型在知识图谱中发现具有群聚性的节点,可用于欺诈团体、企业族群发现等场景</p>
            <p>支持根据关系类型构建子图网络，进行计算</p>
        </div>

        <div class="col-md-12">
            <div class="panel panel-default ">
                <header class="panel-heading">
                    条件设置
                </header>

                <div class="panel-body layui-form">
                    <!--搜索框-->
                    <div>
                        <div class="input-group layui-inline">
                            <label class="layui-form-label">子图</label>
                            <div class="layui-input-inline">
                                <select id='grouplayfilterid' name="modules" lay-verify="required" lay-search=""
                                    lay-filter="grouplayfilter">
                                    <option value="">选取子图关系</option>

                                    <option value="不限关系">不限关系</option>
                                    <option value="控股">控股</option>
                                    <option value="法人代表">法人代表</option>

                                </select>

                            </div>
                        </div>



                        <div class="layui-inline">
                            <div class="btn-group layui-inline" style="padding: 2%">
                                <button type="button" id="groupbtn" class="btn btn-primary">
                                    执行模型
                                </button>


                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div>
            <table id="showgroup" lay-filter="showgroup"></table>
        </div>

        <div class="col-md-12">
            <ol class="breadcrumb">
                <li><i class="fa fa-share-alt" aria-hidden="true"></i>pankrange模型</li>
            </ol>
            <p>pankrange模型用于计算节点在网络中的权重指数，可以用于发现中心节点等</p>
            <p>支持根据关系类型构建子图网络，进行计算</p>

        </div>

        <div class="col-md-12">
            <div class="panel panel-default ">
                <header class="panel-heading">
                    条件设置
                </header>

                <div class="panel-body layui-form">
                    <!--搜索框-->
                    <div>
                        <div class="input-group layui-inline">
                            <label class="layui-form-label">子图</label>
                            <div class="layui-input-inline">
                                <select id='pankrangelayfilterid' name="modules" lay-verify="required" lay-search=""
                                    lay-filter="pankrangelayfilter">
                                    <option value="">选取子图关系</option>
                                    <option value="不限关系">不限关系</option>
                                    <option value="控股">控股</option>
                                    <option value="法人代表">法人代表</option>
                                </select>

                            </div>
                        </div>


                        <div class="layui-inline">
                            <div class="btn-group layui-inline" style="padding: 2%">
                                <button type="button" id="pankrangebtn" class="btn btn-primary">
                                    执行模型
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div>
            <table id="pankrange" lay-filter="pankrange"></table>
        </div>


        <script>
            function creategrouptables(communitytype) {
                layui.use(['layer', 'table'], function () {
                    var layer = layui.layer
                        , $ = layui.jquery
                        , table = layui.table
                    //展示已知数据
                    tableField = [ //表头
                    , { field: 'grouptype', title: '社区类型' }
                     ,  { field: 'groupid', title: '社区编号', event: 'groupclick', style: 'cursor: pointer;' }
                        , { field: 'groupcount', title: '社区成员个数', sort: true }
                    ];
                    var form_data = new FormData();
                    form_data.append("groupkey", communitytype);
                    $.ajax({
                        url: '../getgrouplist/',
                        type: 'post',
                        data: form_data,
                        //async:false,
                        processData: false,
                        contentType: false,
                        success: function (data) {
                            //console.log(data)
                            //var data=[{groupid:2,groupcount:3}]
                            table.render({
                                elem: '#showgroup'
                                , cellMinWidth: 80
                                , data: data.data
                                , page: true //开启分页
                                , cols: [tableField]
                            });
                        },
                    });

                    table.on('tool(showgroup)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'groupclick') {
                            //alert(data.groupid)
                            var loading = layer.load(0, {
                                shade: false,
                                time: 120 * 1000
                            });
		
                            var neosql='match r=(n) where n.`'+data.grouptype+'`='+data.groupid+' return r limit 50'
                            $.post("/com_query", JSON.stringify({ "neosql": neosql }), function (data, status)
							{
                                if (status === "success") {
                                    //console.log(data)
                                   //$.post("/grap_view", JSON.stringify(data), function (cur_data, status) {
                               //} )
                               layer.close(loading);
                               window.open("/grap_view?data="+JSON.stringify(data),'_blank')
                            }
								
								else {
                                    layer.close(loading);
                                    layer.msg('调用接口失败', { icon: 5 });
                                }
                            })

                        }
                    });

                })
            }
        </script>

        <script>
            function createpankrangetables(pankrangetype) {
                layui.use(['layer', 'table'], function () {
                    var layer = layui.layer
                        , $ = layui.jquery
                        , table = layui.table
                    //展示已知数据
                    tableField = [ //表头
                        { field: 'pgtype', title: '类型' }
                        , { field: 'pgname', title: '名称', event: 'pgnameclick', style: 'cursor: pointer;' }
                        , { field: 'pgweight', title: '权重值', sort: true }
                    ];
                    var form_data = new FormData();
                    form_data.append("pgkey", pankrangetype);
                    $.ajax({
                        url: '../getpglist/',
                        type: 'post',
                        data: form_data,
                        //async:false,
                        processData: false,
                        contentType: false,
                        success: function (data) {
                            //console.log(data)
                            //var data=[{groupid:2,groupcount:3}]
                            table.render({
                                elem: '#pankrange'
                                , cellMinWidth: 80
                                , data: data.data
                                , page: true //开启分页
                                , cols: [tableField]
                            });
                        },
                    });


                    table.on('tool(pankrange)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'pgnameclick') {
                            var loading = layer.load(0, {
                                shade: false,
                                time: 120 * 1000
                            });
                            //alert(data.pgtype+data.pgname);
                            var neosql='MATCH r=(n:`'+data.pgtype+'`) WHERE n.name=\''+data.pgname+'\' return r'
                            $.post("/com_query", JSON.stringify({ "neosql": neosql }), function (data, status)
							{
                                if (status === "success") {
                                    //console.log(data)
                                   //$.post("/grap_view", JSON.stringify(data), function (cur_data, status) {
                               //} )
                               layer.close(loading);
                               window.open("/grap_view?data="+JSON.stringify(data),'_blank')
                            }
								
								else {
                                    layer.close(loading);
                                    layer.msg('调用接口失败', { icon: 5 });
                                }
                            })
                        }
                    });


                })
            }
        </script>
        <!--div class="col-md-12">
            <ol class="breadcrumb">
                <li><i class="fa fa-share-alt" aria-hidden="true"></i>循环路径模型</li>
            </ol>
            <p>循环路径模型用于发现网络中的闭环路径，可用于循环担保、循环转账发现等场景</p>
            <p>支持目标实体、边类型、路径长度、有向图/无向图的参数配置</p>

        </div>

        <div class="col-md-12">
            <div class="panel panel-default ">
                <header class="panel-heading">
                    条件设置
                </header>

                <div class="panel-body layui-form">
                     <div>

                        <div class="input-group layui-inline">
                            <label class="layui-form-label">实体</label>
                            <div class="layui-input-inline">
                                <select id='circleenlayfilterid' name="modules" lay-verify="required" lay-search=""
                                    lay-filter="circleenlayfilter">
                                    <option value="">选取目标实体类型</option>
                                    <option value="公司">公司</option>
                                    <option value="人">人</option>
                                </select>

                            </div>
                        </div>

                        <div class="input-group layui-inline">
                            <label class="layui-form-label">边</label>
                            <div class="layui-input-inline">
                                <select  id='circlerelayfilterid'  name="modules" lay-verify="required" lay-search=""
                                    lay-filter="circlerelayfilter">
                                    <option value="">选取边类型</option>
                                    <option value="不限类型">不限类型</option>
                                    <option value="控股">控股</option>
                                    <option value="法人代表">法人代表</option>
                                </select>

                            </div>
                        </div>

                        <div class="input-group layui-inline">
                            <label class="layui-form-label">长度</label>
                            <div class="layui-input-inline">
                                <select   id='circlelenlayfilterid'    name="modules" lay-verify="required" lay-search=""
                                    lay-filter="circlelenlayfilter">
                                    <option value="">选取最大路径长度</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                </select>

                            </div>
                        </div>

                        <div class="input-group layui-inline">
                            <label class="layui-form-label">方向</label>
                            <div class="layui-input-inline">
                                <select id='circleforlayfilterid' name="modules" lay-verify="required" lay-search=""
                                    lay-filter="circleforlayfilter">
                                    <option value="">是否限制路径方向</option>
                                    <option value="0">无向图</option>
                                    <option value="1">有向图</option>
                                </select>

                            </div>
                        </div>

                        <div class="layui-inline">
                            <div class="btn-group layui-inline" style="padding: 2%">
                                <button type="button" id="circlebtn" class="btn btn-primary">
                                    执行模型
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div-->



    </div>
    <p>

    </p>
</div>
<script>


    $("#groupbtn").click(function () {
        //layer.close(loading);
        var stren_cont = $("#grouplayfilterid option:selected").val()//执行
        if (stren_cont == "") {
            layer.alert('请配置条件', { icon: 2 })
            return
        }
        var loading = layer.load(0, {
            shade: false,
            time: 120 * 1000
        });
        var form_data = new FormData();
        form_data.append("retype", stren_cont);
        $.ajax({
            url: "/group_math/",
            type: "POST",
            data: form_data,
            //async: false,
            contentType: false,
            processData: false,
            success: function (cur_data) {
                layer.close(loading);
                ShowData = '执行完成<br>执行详情:<br>' + cur_data['执行详情']
                layer.alert(ShowData, { icon: 6 });
                creategrouptables('community_' + stren_cont)
            },
            error: function () {
                layer.msg('调用接口失败', { icon: 5 });
                layer.close(loading);
            }
        })

    });
    $("#pankrangebtn").click(function () {
        //layer.close(loading);
        var stren_cont = $("#pankrangelayfilterid option:selected").val()//执行
        if (stren_cont == "") {
            layer.alert('请配置条件', { icon: 2 })
            return
        }
        var loading = layer.load(0, {
            shade: false,
            time: 120 * 1000
        });
        var form_data = new FormData();
        form_data.append("retype", stren_cont);
        $.ajax({
            url: "/pankrange_math/",
            type: "POST",
            data: form_data,
            //async: false,
            contentType: false,
            processData: false,
            success: function (cur_data) {
                layer.close(loading);
                ShowData = '执行完成<br>执行详情:<br>' + cur_data['执行详情']
                layer.alert(ShowData, { icon: 6 });
                createpankrangetables('pagerank_' + stren_cont)
            },
            error: function () {
                layer.msg('调用接口失败', { icon: 5 });
                layer.close(loading);
            }
        })

    });

</script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        form.render();

        form.on('select(grouplayfilter)', function (data) {
            //alert(data.value);
            creategrouptables('community_' + data.value)
        });

        form.on('select(pankrangelayfilter)', function (data) {
            //alert(data.value);
            createpankrangetables('pagerank_' + data.value)

        });
        /*
        form.on('select(circleenlayfilter)', function (data) {
            //alert(data.value);
        });

        form.on('select(circlerelayfilter)', function (data) {
            //alert(data.value);
        });
        form.on('select(circlelenlayfilter)', function (data) {
            //alert(data.value);
        });
*/

    });




</script>
{% endblock %}